global class accountQueryController {
        
    public Id id;
    public Contact contact;
    public Account account;
    public List<Employee_relative_del__c> relatives;
    public List<Commute__c> commutes;
    public List<Course_Participant__c> courses;
    public List<Education__c> educations;
    public List<Work_History__c> histories;
    
    
    public accountQueryController(){
        try{
            //id = '001L0000005XmWdIAK';
            id = ApexPages.currentPage().getParameters().get('id');
            if(id!=null){
                contact = getContact();
                                account = getAccount();
            }
        }catch(System.QueryException ex){
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Id does not exist in Employee') );
                }
    } 
    
    public contact getContact(){
        Contact query;
        try {
                query = [SELECT Id, AccountId, Salutation, FirstName, LastName FROM Contact where id = :id ];
                if(query == null) query = new Contact();
        } catch(System.QueryException ex){
                        System.debug('An error has ocurred (accountQueryController): getContact '+ex.getMessage()); 
                }
        return query;
    }
    
    public Account getAccount(){
        Account query;
        try {
                query = [SELECT Id, FirstName, LastName, Salutation, Height__c, Weight__c, PersonEmail, CurrencyIsoCode, Birthdate__c, 
                     Willing_to_travel__c, Marital_status__c, States_where_I_have_family__c, 
                     isPersonAccount, Who_cares_them__c, BillingStreet, BillingCity, BillingState, 
                     BillingPostalCode, AccountNumber, Position__r.Name, Current_Store__r.Name, Join_date__c, 
                     Coat__c, Vest__c, Pants__c, Shirt__c, Face_Photo_ID__c, Body_Photo_ID__c 
                    FROM Account 
                    WHERE id=:id ];
                if(query == null) query = new Account();
        } catch(System.QueryException ex){
                        System.debug('An error has ocurred (accountQueryController): getAccount '+ex.getMessage()); 
                }
        return query;
    }
    
    public List<Employee_relative_del__c> getRelatives(){
        try{
                if(account.Id!=null){
                relatives = [SELECT Name, Relationship__c, Phone__c, Occupation__c FROM Employee_relative_del__c WHERE Employee__c=: account.Id];
                }
        }catch(Exception ex){
                System.debug('An error has ocurred (accountQueryController): getRelatives '+ex.getMessage()); 
        }
        return relatives;
    }
    
    public List<Commute__c> getCommutes(){
        try{
                if(account.Id!=null){
                        commutes = [SELECT Store__r.Name, Transfer_Time__c, Cost__c, Route__c FROM Commute__c WHERE Account__c=: account.Id];
                }
        }catch(Exception ex){
                System.debug('An error has ocurred (accountQueryController): getCommutes '+ex.getMessage()); 
        }
        return commutes;
    }
    
    public List<Course_Participant__c>    getCourses(){
        try{
                if(account.Id!=null){
                        courses = [SELECT Course__r.Name, Due_date__c, Number_Tried__c, Score__c, Exam_Approved__c FROM Course_participant__c WHERE Employee__c =: account.Id];
            }
                } catch(Exception ex) {
                System.debug('An error has ocurred (accountQueryController): getCourses '+ex.getMessage());
        }        
        return courses;
    }
    
    public List<Education__c> getEducations(){
        try{
                if(account.Id!=null){
                        educations = [SELECT Study_Level__c, Title__c, Institution_Name__c, From__c, To__c FROM Education__c WHERE Employee__c=: account.Id];
                }
        }catch(Exception ex){
                System.debug('An error has ocurred (accountQueryController): getEducations '+ex.getMessage());
        }
        return educations;
    }
    
    public List<Work_History__c> getHistories(){
        try{
                if(account.Id!=null){
                        histories = [SELECT Company__c, Position__c, Reason_for_leaving__c, Seniority_yrs__c FROM Work_History__c WHERE Employee__c=: account.Id];
                }
                }catch(Exception ex){
                        System.debug('An error has ocurred (accountQueryController): getHistories '+ex.getMessage());
                }       
        return histories;
    }
}